package com.loongtech.bi.manager.game;

import com.loongtech.bi.entity.game.EntityActiveUser1LevelDistribute;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
/**
 * 用户的三日流失
 * @author lihui
 *
 */
@Service
public class ActiveUser1LevelDistributeManager extends ManagerQueryCacheBase<EntityActiveUser1LevelDistribute> {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 
	 * @param dayDate
	 * @param queryPlatform
	 * @param queryChannel
	 * @param queryServer
	 * @return
	 */
	public List<Object[]> getAllKindUserNumberGroupByLevel(Date dayDate,String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select level,sum(user_number) from EntityActiveUser1LevelDistribute where day =:dayDate and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' group by level order by sum(user_number) desc", "dayDate", dayDate);
	}
	
	/**
	 * 
	 * @param dayDate
	 * @param queryPlatform
	 * @param queryChannel
	 * @param queryServer
	 * @return
	 */
	public List<Object[]> getAllKindUserNumber(Date dayDate,String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select sum(user_number),count(user_number) from EntityActiveUser1LevelDistribute where day =:dayDate and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"'", "dayDate", dayDate);
	}
	
	/**
	 * 
	 * @param startDate
	 * @param endDate
	 * @param queryPlatform
	 * @param queryChannel
	 * @param queryServer
	 * @param minLevel
	 * @return
	 */
	public List<Object[]> getAllKindUserNumberGroupByLevel(Date startDate, Date endDate, String queryPlatform, String queryChannel, String queryServer, int minLevel) {
		return findByQuery("select date_format(day,'%Y-%m-%d'),level,user_number from EntityActiveUser1LevelDistribute where day>=:startDate and day<=:endDate and platformid=:queryPlatform and channelid=:queryChannel and serverid=:queryServer and level >= :minLevel ",
				"startDate", startDate,
				"endDate", endDate,
				"queryPlatform", queryPlatform,
				"queryChannel", queryChannel,
				"queryServer", queryServer,
				"minLevel", minLevel);
	}
}
